﻿<%@ Page Language="C#" Title="交通量轴载" MasterPageFile="~/W_View/PageMaster.Master" CodeBehind="Dm_TrafaxlePage.aspx.cs" Inherits="STHPMS1.Web.W_View.Decision.Dm_TrafaxlePage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <%= UiHelper.RefJsFileHtml("/Scripts/Control/datagrid.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/Control/dropdown.js")%>

    <script type="text/javascript">
        var _pvmttypeId;
        var _mainsegid;
        function Dm_TrafaxleEdit(flag) {
            var row = $('#dg').datagrid('getSelected');
            var title = "";
            if (flag == 0) {
                if (!row) {
                    $.messager.alert('消息提示', '编辑数据时，请选择一项!', 'warning');
                    return;
                }
                var rect = {};
                rect.id = row.Rdwayid;
                rect.Pvmttype_Dictid = row.Pvmttype_Dictid;
                _mainsegid = row.Mainsegid;

                $('#fm').form('load', row);
                reqSeg(rect);
                reqSurface(rect);

                setTrafficrank();
                title = "新增测试数据";
            }
            else {
                $('#fm').form('clear');
                title = "编辑测试数据";
            }

            $('#dlg').dialog('open');
        }

        function Dm_TrafaxleDel() {
            var row = $('#dg').datagrid('getSelected');
            if (!row) {
                $.messager.alert('消息提示', '删除数据时，请选择一项!', 'warning');
                return;
            }

            deleteData($('#dg'), $('#dlg'), "/api/trafaxle");
        }

        function sync_Trafaxle() {
            var rdwayid = $('#cmbRoads').combobox("getValue");
            if (!rdwayid) {
                $.messager.alert('消息提示', '请选择一条路线!', 'warning');
                return;
            }

            $.ajax({
                url: '/api/trafaxle/sync?rdwayid=' + encodeURI(rdwayid),
                type: "post",
                success: function (data1) {
                    $('#dg').datagrid('reload');
                },
                error: function (err) {
                    $.messager.alert('错误提示', err.responseJSON.ExceptionMessage, 'error');
                }
            });
        }


        function search(n, o) {
            var road = $('#cmbRoads').combobox("getValue");

            var url = '/api/trafaxle';
            var urlParam = "";
            if (road != "" && road != "0") urlParam += "road=" + encodeURI(road) + "&";
            if (urlParam != "") {
                urlParam = "?" + urlParam.substring(0, urlParam.length - 1);
                url = url + urlParam;
            }

            $('#dg').datagrid({ url: url, pageNumber: 1 });
        }

        $(function () {
            var number = '<%= Page.RouteData.Values["page"] %>';
            var size = '<%= Page.RouteData.Values["size"] %>';

            dataGridBind($('#dg'), '/api/trafaxle', '交通量轴载显示', $('#tb'), number, size);

            $('.validatebox-text').bind('blur', function () {
                $(this).validatebox('enableValidation').validatebox('validate');
            });


        })

        
        function setTrafficrank() {
            //沥青路面 21(165-167) 水泥路面 22(168-171) 砂石路面 23 (172)
            var esal = $('#Esal').numberbox('getValue');
            if (!esal) return;
            var type = $('#Pvmttype_Dictid').combobox('getValue');
            if (!type) return;
            var value;
            var label;
            if (type > 164 && type < 168) {
                if (esal > 25000000) {
                    value = 4001;
                    label = "特重";
                }
                else if (esal > 12000000) {
                    value = 4002;
                    label = "重";
                }
                else if (esal > 3000000) {
                    value = 4003;
                    label = "中等";
                } else {
                    value = 4004;
                    label = "轻";
                }
            } else if (type > 167 && type < 172) {
                if (esal > 2000000) {
                    value = 4001;
                    label = "重";
                }
                else if (esal > 1000000) {
                    value = 4002;
                    label = "特重";
                }
                else if (esal > 30000) {
                    value = 4003;
                    label = "中等";
                } else {
                    value = 4004;
                    label = "轻";
                }
            }
            else if (type < 173) {

            }
            if (value)
                $('#Trafficrank').numberbox('setValue', value);
            if (label)
                $('#t').val(label);
        }

        function reqSeg(rect)
        {
            $('#Mainsegid').combobox('clear');
            $('#Pvmttype_Dictid').combobox('clear');

            $.ajax({
                url: '/api/trafaxle/seg?rdwayid=' + rect.id,
                success: function (data1) {
                    type = null;

                    $('#Mainsegid').combobox('loadData', data1);
                },
                error: function (err) {
                    $.messager.alert('错误提示', '获取养护路段数据错误 -' + err, 'error');
                }
            });
        }

        function reqSurface(rect){                   
                                
            $.ajax({                
                url:'/api/data/roadsurface',
                success: function (data1) {
                    _pvmttypeId = rect.Pvmttype_Dictid;

                    $('#Pvmttype_Dictid').combobox('loadData', data1);
                    setTrafficrank();
                },
                error: function (err) {
                    $.messager.alert('错误提示', '获取养护路段数据错误 -' + err, 'error');
                }
            });
                                                      
                            
        }
    </script>    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <table id="dg" class="easyui-datagrid content-place"  ajaxCached="false"  >
        <thead>
            <tr>
                <th data-options="field:'Trafaxleid',editor:'text',width:80,align:'right' ,hidden:true">交通量轴载ID</th>
                <th data-options="field:'Rdwayid',editor:'text',width:80,align:'right' ">路线编号</th>
                <th data-options="field:'Mainsegid',editor:'text',width:80,align:'right' ">养护路段</th>
                <th data-options="field:'Pvmttype_Dictid',editor:'numberbox',width:200,align:'right' " formatter="formatRoadSurface">路面类型</th>   
                <th data-options="field:'Traf_Svydata',editor:'datebox',width:100,align:'right' " formatter="formatDate" >交通量调查日期</th>
                <th data-options="field:'Axle_Svydata',editor:'datebox',width:100,align:'right' " formatter="formatDate" >轴载调查日期</th>
                <th data-options="field:'Curadt',editor:'numberbox',width:80,align:'right' " formatter="formatNumber">当前AADT</th>
                <th data-options="field:'Curadtyear',editor:'text',width:80,align:'right' ">当前AADT年份</th>
                <th data-options="field:'Rdtrf',editor:'numberbox',width:80,align:'right' ">交通量增长率(%)</th>
                <th data-options="field:'Lanecoef',editor:'numberbox',width:80,align:'right' ">车道系数</th>
                <th data-options="field:'Disspltpct',editor:'numberbox',width:80,align:'right' ">方向系数</th>
                <th data-options="field:'Design_Year',editor:'numberbox',width:80,align:'right' ">设计年限（年）</th>
                <th data-options="field:'Esal',editor:'numberbox',width:80,align:'right' "  formatter="formatNumber">累计当量轴载</th>
                <th data-options="field:'Trafficrank',editor:'numberbox',width:80,align:'right' "  formatter="formatTrafficrank">交通等级</th>             
            </tr>
        </thead>
    </table>
   
     <div id="tb">
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="Dm_TrafaxleEdit(-1)">添加</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="Dm_TrafaxleEdit(0)">修改</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="Dm_TrafaxleDel()">删除</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" onclick="sync_Trafaxle()">同步</a>
        <select id="cmbRoads" class="easyui-combobox" panelHeight="80" style="width:100px" data-options="prompt:'路线编号',url:'/api/roadway/dict',method:'get',valueField:'id',textField:'id',onChange:search">
        </select>
    </div>

    <div id="dlg" class="easyui-dialog" title="保存数据" style="width:400px;height:400px;padding:10px" closed="true"  data-options="
				iconCls: 'icon-save',
				buttons: '#dlg-buttons' ">
            <form id="fm" method="post" action="/api/trafaxle">
                <table>
                    <tr  style="display:none">
                        <td>交通量轴载ID:</td>
                        <td><input name='Trafaxleid' class='easyui-validatebox easyui-textbox'  /></td>
                    </tr>
                    <tr>
                        <td>路线编号:</td>
                        <td><input id="Rdwayid" name='Rdwayid'  class="easyui-validatebox  easyui-combobox" data-options="prompt:'路线编号',required:true,valueField:'id',textField:'id',url:'/api/roadway/dict',method:'get',validType:'MaxLength[20]' ,onSelect:reqSeg"/></td>
                    </tr>
                    <tr>
                        <td>养护路段:</td>
                        <td><input id="Mainsegid" name='Mainsegid' class="easyui-validatebox  easyui-combobox" data-options="prompt:'养护路段',required:true,valueField:'Mainsegid',textField:'Mainsegid' ,method:'get',onSelect:reqSurface,
                            onLoadSuccess:function(data){ $('#Mainsegid').combobox('setValue',_mainsegid); _mainsegid=null;}"/></td>
                    </tr>
                    <tr>
                        <td>路面类型:</td>
                        <td><input id="Pvmttype_Dictid" name='Pvmttype_Dictid'  class="easyui-combobox" data-options="readonly:true,prompt:'路面类型',valueField:'id',textField:'text',method:'get' ,
                            onLoadSuccess:function(data){ $('#Pvmttype_Dictid').combobox('setValue',_pvmttypeId); _pvmttypeId=null;} " /></td>
                    </tr>
                    <tr>
                        <td>当前AADT:</td>
                        <td><input name='Curadt' class='easyui-validatebox easyui-numberbox'  data-options='required:true, min:0,precision:2' /></td>
                    </tr>
                    <tr>
                        <td>当前AADT年份:</td>
                        <td><input name='Curadtyear' class="easyui-validatebox  easyui-combobox" data-options="prompt:'Curadtyear',valueField:'id',textField:'id' ,method:'get',url:'/api/data/years' "/></td>
                    </tr>
                    <tr>
                        <td>交通量调查日期:</td>
                        <td><input name='Traf_Svydata' class='easyui-validatebox easyui-datebox'  /></td>
                    </tr>
                    <tr>
                        <td>轴载调查日期:</td>
                        <td><input name='Axle_Svydata' class='easyui-validatebox easyui-datebox'  /></td>
                    </tr>
                    <tr>
                        <td>交通量增长率(%):</td>
                        <td><input name='Rdtrf' class='easyui-validatebox easyui-numberbox'  data-options='min:0,precision:2' /></td>
                    </tr>
                    <tr>
                        <td>车道系数:</td>
                        <td><input name='Lanecoef' class='easyui-validatebox easyui-numberbox'  data-options='min:0,precision:2' /></td>
                    </tr>
                    <tr>
                        <td>方向系数:</td>
                        <td><input name='Disspltpct' class='easyui-validatebox easyui-numberbox'  data-options='min:0,precision:2' /></td>
                    </tr>
                    <tr>
                        <td>设计年限（年）:</td>
                        <td><input name='Design_Year' class='easyui-validatebox easyui-numberbox' /></td>
                    </tr>
                    <tr>
                        <td>累计当量轴载:</td>
                        <td><input id="Esal"  name='Esal' class='easyui-validatebox easyui-numberbox'  data-options="min:0,precision:2,onChange:setTrafficrank" /></td>
                    </tr>
                    <tr>
                        <td>交通等级</td>
                        <td><input id="t" readonly="readonly" /></td>
                    </tr>
                    <tr style="display:none">
                        <td></td>
                        <td><input id="Trafficrank" name='Trafficrank'class="readonly:true,min:0,precision:2,easyui-validatebox easyui-numberbox"/></td>
                    </tr>
		        </table>
            </form>
    </div>

    <!--编辑数据命令-->
    <div id="dlg-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:sumbitData($('#dg'),$('#dlg'))">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#dlg').dialog('close')">取消</a>
	</div>
</asp:Content>
